Skip to content

feat(cache): prune expired entries on startup#8

Open
silicon-intern wants to merge 1 commit intoggonzalez94:mainfrom
silicon-intern:cache-eviction
Open

feat(cache): prune expired entries on startup#8
silicon-intern wants to merge 1 commit intoggonzalez94:mainfrom
silicon-intern:cache-eviction

Conversation

@silicon-intern
Copy link

What

Adds a Prune() method to cache.Store that deletes all rows where created_at + ttl_seconds < now(). It is called automatically during Open() so that every CLI invocation cleans up stale data before proceeding.

Why

The cache currently grows indefinitely — entries are written with TTL metadata but never deleted. For agents or scripts calling the CLI frequently, cache.db accumulates stale rows without bound.

Changes

  • internal/cache/cache.go: Add Prune() method; call it in Open()
  • internal/cache/cache_test.go: Add TestPruneRemovesExpiredEntries

Closes #5

Add a Prune() method to cache.Store that deletes rows where
created_at + ttl_seconds < now. Called automatically during Open()
to prevent unbounded cache growth.

Closes ggonzalez94#5
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adad6e060a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

return nil
}
nowUnix := time.Now().UTC().Unix()
_, err := s.db.Exec("DELETE FROM cache_entries WHERE created_at + ttl_seconds < ?", nowUnix)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve stale fallback window when pruning cache rows

runCachedCommand intentionally serves expired entries during temporary provider failures when they are within max_stale, but this delete condition removes rows immediately after TTL (created_at + ttl_seconds < now) during every Open() call. Because the CLI is typically a new process per command, entries that should be valid for stale fallback are deleted before the provider fetch path runs, so users lose the documented TTL+max-stale recovery behavior and see hard failures instead of stale fallback.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache grows indefinitely — no eviction of expired entries

1 participant